// 两数之和

let twoSum = function (nums, target) {
  let hash = {};
  for (let i = 0; i < nums.length; i++) {  // 遍历当前元素，并在map中寻找是否有匹配的key
    if (hash[target - nums[i]] !== undefined) {
      return [i, hash[target - nums[i]]];
    }
    hash[nums[i]] = i;   // 如果没找到匹配对，就把访问过的元素和下标加入到map中
  }
  return [];
};

console.log(twoSum([2, 7, 11, 15, 34, 78], 9));